home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: mvb.saic.com!eskimo!news
- From: mag@eskimo.com (mAg)
- Subject: Re: Checking for a file => Does it exist (Help)
- X-Nntp-Posting-Host: tia1.eskimo.com
- Message-ID: <DL9GIA.4y1@eskimo.com>
- Sender: news@eskimo.com (News User Id)
- Organization: *.*
- References: <4d9k6fINNnja@faatcrl.faa.gov> <4dc6kq$dja@gryphon.phoenix.net>
- Date: Tue, 16 Jan 1996 06:25:21 GMT
-
- In article <4dc6kq$dja@gryphon.phoenix.net> (Mon, 15 Jan 1996 01:00:31 GMT),
- brucew@phoenix.net says :
- >
- >afrawert@faatcrl.faa.gov (Alan Frawert) wrote:
- >
- >
- >>I'm having a problem just checking to see if a file
- >>exists. Does anyone have a simple piece of code that I can use?
- >
- >Well, you could try to open it then close it:
- >
- >int file_exist( char *fname)
- >{
- > int flag = 0;
- > FILE *fp = fopen( fname, "r");
- > flag = fp ? 1 : 0;
- > fclose(fp);
- > return flag;
- >}
- >
-
- Just a little smarter(?) version :-)
-
- int file_exist(char *fname)
- {
- FILE *fp;
- if (fp = fopen(fname,"r"))
- {
- fclose(fp);
- return(1);
- }
- return (0);
- }
-
- --
- /* --------------------------------------------------------
- MAG@ESKIMO.COM
- http://www.eskimo.com/~mag/index.html
- ***********************************************************
- To understand recursion one must first understand recursion
- ***********************************************************
- -------------------------------------------------------- */
-
-